﻿Imports System.Data.SqlClient

Public Class passwordFind
    Inherits System.Web.UI.Page
    Private objrd As SqlDataReader = Nothing
    Private objexecute As New GetData
    Private sSQL As String
    Private ps As New PreparedStatement(sSQL)


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click

        Dim strErr As String = ""
        ps.addParameter("email", email.Text)
        sSQL = "select * from member where email=@email"
        ps.strSql = sSQL
        Dim conn As SqlConnection = objexecute.getConn()

        objrd = objexecute.dr(ps, strErr, conn, objrd)
        If objrd.Read() Then
            Dim uid As String
            uid = System.Guid.NewGuid().ToString()
            '创建发件连接,根据你的发送邮箱的SMTP设置填充
            Dim smtp As New System.Net.Mail.SmtpClient("smtp.georgia-globaltp.com", 587)

            '发件邮箱身份验证,参数分别为 发件邮箱登录名和密码
            smtp.Credentials = New System.Net.NetworkCredential("support@georgia-globaltp.com", "admin606")
            '创建邮件
            Dim mail As New System.Net.Mail.MailMessage()
            '邮件主题
            mail.Subject = "密码找回"
            '主题编码
            mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312")
            '邮件正文件编码
            mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312")
            '发件人邮箱
            mail.From = New System.Net.Mail.MailAddress("support@georgia-globaltp.com")
            '邮件优先级
            mail.Priority = System.Net.Mail.MailPriority.Normal
            'HTML格式的邮件,为false则发送纯文本邮箱
            mail.IsBodyHtml = True
            Dim code As String
            Dim sha As New SHA1
            code = sha.mySHA(email.Text & uid)
            '邮件内容
            mail.Body = "http://" & Request.ServerVariables("http_host") & Request.ServerVariables("Url").Replace("find", "edit") & "?email=" & email.Text & "&code=" & code & ""
            '添加收件人,如果有多个,可以多次添加
            mail.To.Add(email.Text)
            '发送邮件
            Try
                smtp.Send(mail)
                ps.addParameter("code", uid)
                ps.addParameter("exp", Now().AddDays(1))
                ps.strSql = "update member set check_code=@code,check_code_exp=@exp where email=@email"
                objexecute.es(ps, strErr)
                If strErr = Nothing Or strErr = "" Then
                    Response.Redirect("cn_password_success.aspx?email=" & email.Text & "")
                End If
            Catch
                'alert("发送失败")
            Finally
                mail.Dispose()
            End Try
            objexecute.closeConn(conn)

        End If
    End Sub
End Class